/* 
* sapdp-core.c
*
* Copyright (c) 2010, Zachary N J Peterson <znpeters@nps.edu>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of the Naval Postgraduate School nor the
*       names of its contributors may be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ZACHARY N J PETERSON ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ZACHARY N J PETERSON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "sapdp.h"
#define SIZE 26
#define BLOCKSIZE (1UL << SIZE)

int main(int argc, char **argv){

	SAPDP_client_tag *ctag = NULL;
	SAPDP_server_tag *stag = NULL;
	DPDP_tag *tag = NULL;
	SAPDP_key *key = NULL;
	DPDP_key *dpdp_key = NULL;
	unsigned char *block;
	unsigned int i = 0;


	block = malloc(BLOCKSIZE);

	key = sapdp_generate_key();
	if(!key) return -1;

	dpdp_key = dpdp_generate_key();
	if(!dpdp_key) return -1;
	
	if(!RAND_bytes(block, BLOCKSIZE)) return -1;

	for(i = 0; i < SIZE + 1; i++){
		printf("File size %lu\n", (1UL << i));
	

/*
		gettimeofday(&tv1, NULL);	
		printf("\tGenerating server tag...");
		fflush(stdout);
		stag = sapdp_server_tag_block(key, ctag);
		if(!stag) printf("Did not generate a server tag\n");
		else printf("Done.\n");
		gettimeofday(&tv2, NULL);
		printf("\t%lf\n", (double)( (double)(double)(((double)tv2.tv_sec) + (double)((double)tv2.tv_usec/1000000)) - (double)((double)((double)tv1.tv_sec) + (double)((double)tv1.tv_usec/1000000)) ) );
*/


		//printf("\tGenerating DPDP tag...");
		fflush(stdout);
		tag = dpdp_tag_block(dpdp_key, block, (1UL << i));
		if(!tag) printf("Did not generate DPDP tag\n");
	//	else printf("Done.\n");


		//printf("\tGenerating client tag...");
		fflush(stdout);
		ctag = sapdp_client_tag_block(key, block, (1UL << i), 0);
		if(!ctag) printf("Did not generate a client tag\n");
		//else printf("Done.\n");

	}
	
	return 0;	
}